package model;

import app.PriceInvalidException;

public abstract class Product {
    private String pid;
    private String name;
    private double price;

    public Product(String pid, String name, double price) {
        this.pid = pid;
        this.name = name;
        setPrice(price);
    }

    /* === 新增：子类会用的 getter === */
    public String getPid()   { return pid; }
    public String getName()  { return name; }
    public double getPrice() { return price; }
    /* ================================= */

    public void setPrice(double price) {
        if (price < 0) throw new PriceInvalidException("价格不能为负数：" + price);
        this.price = price;
    }

    public String getBasicInfo() {
        return String.format("编号:%s, 名称:%s, 价格:%.2f", pid, name, price);
    }

    public abstract String getDescription();
}